package com.hao.crm.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hao.crm.domain.Permission;
import com.hao.crm.mapper.PermissionMapper;
import com.hao.crm.page.PageResult;
import com.hao.crm.query.QueryObject;
import com.hao.crm.service.IPermissionService;
@Service
public class PermissionServiceImpl implements IPermissionService{
	@Autowired
	private PermissionMapper dao;
	@Override
	public int delete(Long id) {
		return dao.deleteByPrimaryKey(id);
	}

	@Override
	public int insert(Permission e) {
		return dao.insert(e);
	}

	@Override
	public Permission get(Long id) {
		return dao.selectByPrimaryKey(id);
	}

	@Override
	public List<Permission> selectAll() {
		return dao.selectAll();
	}

	@Override
	public int update(Permission e) {
		return dao.updateByPrimaryKey(e);
	}

	@Override
	public PageResult selectByCondition(QueryObject qo) {
		Long count = dao.queryByConditionCount(qo);
		if(count>0) {
			List<Permission> emps = dao.queryByCondition(qo);
			return new PageResult(count, emps);
		}
		return PageResult.Empty;
	}

	@Override
	public PageResult selectByRid(Long rid) {
		List<Permission> permissions = dao.selectByRid(rid);
		return new PageResult((long) permissions.size(), permissions);
	}

	@Override
	public Permission selectByResouce(String function) {
		return dao.selectByResource(function);
	}

	@Override
	public List<Permission> selectByEid(Long id) {
		return dao.selectByEid(id);
	}

	
	
}
